﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>测试表单验证</title>
    <script src="../resources/scripts/jquery/jquery-1.4.2.js" type="text/javascript"></script>
    <script src="../codes/flareJ.Base.js" type="text/javascript"></script>
    <script type="text/javascript">
        FJ.setRootPath("../");
    </script>
    <script src="../codes/flareJ.DragDrop.js" type="text/javascript"></script>
    <script src="../codes/flareJ.LoadMask.js" type="text/javascript"></script>
    <script src="../codes/flareJ.Panel.js" type="text/javascript"></script>
    <script src="../codes/flareJ.Window.js" type="text/javascript"></script>
    <script src="../codes/flareJ.ToolTip.js" type="text/javascript"></script>
    <script src="../codes/flareJ.Validate.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            //表单验证
            var oVaj1 = $("#unamer").VAJ({
                regMsg: "用户名格式不正确!",
                group: "vaj1",
                msgDirect: "right",
                msgShift: { t: 15, l: 10 },
                regType: "Custom",
                allowBlank: true,
                valElem: "spVaj1",
                regFn: function (p) {
                    var thiz = this;
                    if (FJ.RX.user(p)) {
                        var ret = false;
                        $.ajax({
                            type: "get",
                            url: "../resources/json/testVaj.json",
                            data: { type: "TestUserName", uname: p },
                            cache: false,
                            async: false,
                            success: function (re) {
                                if (re == "true") {
                                    ret = true;
                                }
                                else {
                                    thiz.p.regMsg = "该用户名已存在!";
                                    ret = false;
                                }
                            }
                        });
                        return ret;
                    }
                    else {
                        thiz.p.regMsg = "用户名格式不正确!";
                        return false;
                    }
                }
            });

            var oVaj2 = $("#unamer2").VAJ({
                regMsg: "昵称不能为空!",
                group: "vaj1",
                msgDirect: "right",
                msgShift: { t: 15, l: 10 }
            });

            var oVaj3 = $("#uage").VAJ({
                regMsg: "年龄必须在18-80岁之间!",
                group: "vaj1",
                msgDirect: "right",
                msgShift: { t: 15, l: 10 },
                regType: "Custom",
                allowBlank: true,
                regFn: function (p) {
                    var age = parseInt(p);
                    if (age >= 18 && age <= 80) {
                        return true;
                    }
                    else {
                        return false;
                    }
                }
            });

            var oVaj4 = $("#pass1").VAJ({
                regMsg: "密码格式必须由字母和数字组成,长度为6-16位",
                group: "vaj1",
                msgDirect: "right",
                msgShift: { t: 15, l: 10 },
                regType: "Exp",
                allowBlank: false,
                //regExp: FJ.RX.ep.pass
                regExp: /^[0-9a-zA-Z]{6,16}$/
            });

            var oVaj5 = $("#pass2").VAJ({
                regMsg: "您两次输入的密码不一致",
                group: "vaj1",
                msgDirect: "right",
                msgShift: { t: 15, l: 10 },
                regType: "Equal",
                allowBlank: false,
                inputE: "pass1"
            });

            window.fnSubmit = function () {
                if (VAJ.reg("vaj1")) {
                //if (oVaj1.reg() && oVaj2.reg() && oVaj3.reg() && oVaj4.reg() && oVaj5.reg()) {
                    MBJ.alert("提示", "通过验证!");
                }
                else {
                    MBJ.alert("提示", "您填写的信息有误!");
                }
            };
        });
    </script>
</head>
<body>
    <h3>
        表单验证</h3>
    用户名
    <input id="unamer" style="border: 1px solid #8EB5D4;" type="text" /><span id="spVaj1"
        style="margin-left: 0px;"></span>
    <br />
    <br />
    昵称
    <input id="unamer2" style="border: 1px solid #8EB5D4;" type="text" />
    <br />
    <br />
    密码
    <input id="pass1" style="border: 1px solid #8EB5D4;" type="text" />
    <br />
    <br />
    确认密码
    <input id="pass2" style="border: 1px solid #8EB5D4;" type="text" />
    <br />
    <br />
    年龄
    <input id="uage" style="border: 1px solid #8EB5D4;" type="text" />
    <br />
    <input id="btnVaj" type="button" value="提交表单" onclick="fnSubmit()" />
</body>
</html>
